package com.ngmaster.apiserver.services.impl;

import com.ngmaster.apiserver.config.SocketConfig;
import com.ngmaster.socket.MessageManager;
import com.ngmaster.socket.TcpServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class Server implements ApplicationRunner {

    @Autowired
    private SocketConfig socketConfig;

    public Server() {
        super();
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {

        // 注册消息处理类
        MessageManager.getInstance().init(this.socketConfig);

        // 启动socket服务
        TcpServer tcpServer = new TcpServer();
        tcpServer.init(socketConfig.getPort());
    }
}
